// pages/myself/order/Logistics.js
var Zan = require('../../../dist/index.js');
let network = null;
let utils = null;
let api = null;
const app = getApp();

Page(Object.assign({}, Zan.TopTips, {

  /**
   * 页面的初始数据
   */
  data: {
    logistics: null,
    ename: '',
    expressNo: '',
    orderId:'',
    nodata: {
      msg: '暂无物流信息',
      notype: 1,
      imgurl: '/images/nodatas.png',
      nourl: ''
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    network = new app.NetWorkUtils();
    utils = new app.Utils();
    api = new app.Api();
    this.setData({
      orderId: options.orderId,
      ename: options.ename, // 快递名
      expressNo: options.expressNo// 快递号
    })

    network._post_json(this, api.logistics, { orderId: options.orderId }, success);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    this.setData({
      logistics: null
    })
    network._post_json(this, api.logistics, { orderId: this.data.orderId }, success);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
}))

// 获取订单详情结果
var success = function (that, res) {
  if (res.data.data) {
    let logistics = [];
    for (let i = res.data.data.length - 1; i >= 0; i--) {
      logistics.push(res.data.data[i]);
    }
    that.setData({
      logistics: logistics
    })
  }
}
